package com.augurit.smartform.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.augurit.common.base.dao.BaseDao;
import com.augurit.smartform.entity.SmFunction;

/**
 * 智能表单后端JS对应的DAO类
 */
@Repository
public class SmFunctionDao extends BaseDao<SmFunction,Long>{
	/**
	 * 保存SmFunction的LIST
	 * @param functions
	 * cuigeqiang
	 */
	public void saveFunctions(List<SmFunction> functions){
		for(SmFunction function : functions){
			this.save(function);
		}
	}
	
	/**
	 * 根据SmFunction查询SmFunction的LIST
	 * @param function
	 * @return
	 * cuigeqiang
	 */
	public List<SmFunction> getFunctions(SmFunction function){
		String hql="from SmFunction where pageId=:pageId and fieldId=:fieldId and event=:event";
		return this.getSession().createQuery(hql).setProperties(function).list();
	}
	
	/**
	 * 删除当前页面的后端JS函数
	 * @param pageId
	 * cuigeqiang
	 */
	public void deleteByPageId(Long pageId){
		String sql="delete from sm_function where page_id="+pageId;
		this.getSession().createSQLQuery(sql).executeUpdate();
	}
}
